home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / term43-source.lha / Extras / Source / gtlayout-Source.lha / LTP_DrawGauge.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-21  |  4.5 KB  |  146 lines

  1. /*  GadTools layout toolkit
  2. **
  3. **  Copyright © 1993-1994 by Olaf `Olsen' Barthel
  4. **  Freely distributable.
  5. */
  6.  
  7. #include "gtlayout_global.h"
  8.  
  9. #ifdef DO_GAUGE_KIND
  10. VOID __regargs
  11. LTP_DrawGauge(LayoutHandle *handle,ObjectNode *node,LONG percent,BOOLEAN fullRefresh)
  12. {
  13.     struct RastPort *rp = &handle -> RPort;
  14.  
  15.     if(fullRefresh)
  16.     {
  17.         LONG top = node -> Top + node -> Height - (handle -> RPort . TxHeight + 2);
  18.  
  19.         LTP_SetAPen(rp,handle -> BackgroundPen);
  20.         RectFill(rp,node -> Left,node -> Top,node -> Left + node -> Width - 1,node -> Top + node -> Height - 1);
  21.  
  22.         DrawBevelBox(rp,node -> Left,node -> Top,node -> Width,node -> Height - (handle -> InterHeight + handle -> RPort . TxHeight + 2),
  23.             GT_VisualInfo,    handle -> VisualInfo,
  24.             GTBB_Recessed,    TRUE,
  25.         TAG_DONE);
  26.  
  27.         LTP_SetPens(rp,handle -> TextPen,0,JAM1);
  28.  
  29.         LTP_PlaceText(handle,"0%",2,node -> Left,top + handle -> RPort . TxBaseline);
  30.         LTP_PlaceText(handle,"100%",4,node -> Left + node -> Width - TextLength(rp,"100%",4),top + handle -> RPort . TxBaseline);
  31.  
  32.         if(node -> Width >= TextLength(rp,"0% 50% 100%",11))
  33.         {
  34.             LONG i,left,total = node -> Width - 2;
  35.  
  36.             LTP_PlaceText(handle,"50%",3,node -> Left + (node -> Width - TextLength(rp,"50%",3)) / 2,top + handle -> RPort . TxBaseline);
  37.  
  38.             top -= handle -> InterHeight;
  39.  
  40.             for (i = 0 ; i < 5 ; i++)
  41.             {
  42.                 left = (total * i) / 4;
  43.  
  44.                 RectFill(rp,node -> Left + left,top,node -> Left + left + 1,top + 1);
  45.             }
  46.         }
  47.         else
  48.         {
  49.             LONG i,left,total = node -> Width - 2;
  50.  
  51.             top -= handle -> InterHeight;
  52.  
  53.             for (i = 0; i < 3; i++)
  54.             {
  55.                 left = (total * i) / 2;
  56.  
  57.                 RectFill(rp,node -> Left + left,top,node -> Left + left + 1,top + 1);
  58.             }
  59.         }
  60.     }
  61.  
  62.     if(node -> Special . Gauge . InfoLength && node -> Special . Gauge . InfoText[0])
  63.     {
  64.         LONG            height    = node -> Height - (1 + handle -> InterHeight + handle -> RPort . TxHeight + 2 + 1);
  65.         LONG            width    = node -> Width - (2 + 2);
  66.         LONG            left    = 0;
  67.         LONG            right    = (width * percent) / 100;
  68.         struct TextExtent    Extent;
  69.         LONG            len;
  70.  
  71.         if(right)
  72.         {
  73.             LTP_SetAPen(rp,handle -> DrawInfo -> dri_Pens[FILLPEN]);
  74.  
  75.             RectFill(rp,node -> Left + 2 + left,node -> Top + 1,node -> Left + 2 + right - 1,node -> Top + 1 + height - 1);
  76.         }
  77.  
  78.         if(right < width)
  79.         {
  80.             left    = right;
  81.             right    = width;
  82.  
  83.             LTP_SetAPen(rp,handle -> BackgroundPen);
  84.             RectFill(rp,node -> Left + 2 + left,node -> Top + 1,node -> Left + 2 + right - 1,node -> Top + 1 + height - 1);
  85.         }
  86.  
  87.         if(handle -> DrawInfo -> dri_Pens[FILLTEXTPEN] == handle -> DrawInfo -> dri_Pens[BACKGROUNDPEN])
  88.         {
  89.             if(handle -> DrawInfo -> dri_Pens[TEXTPEN] == handle -> DrawInfo -> dri_Pens[FILLPEN])
  90.                 LTP_SetPens(rp,handle -> DrawInfo -> dri_Pens[TEXTPEN],handle -> BackgroundPen,JAM1 | COMPLEMENT);
  91.             else
  92.                 LTP_SetPens(rp,handle -> DrawInfo -> dri_Pens[TEXTPEN],handle -> BackgroundPen,JAM1);
  93.         }
  94.         else
  95.         {
  96.             if(handle -> DrawInfo -> dri_Pens[FILLTEXTPEN] == handle -> DrawInfo -> dri_Pens[FILLPEN])
  97.                 LTP_SetPens(rp,handle -> DrawInfo -> dri_Pens[FILLTEXTPEN],handle -> BackgroundPen,JAM1 | COMPLEMENT);
  98.             else
  99.                 LTP_SetPens(rp,handle -> DrawInfo -> dri_Pens[FILLTEXTPEN],handle -> BackgroundPen,JAM1);
  100.         }
  101.  
  102.         len = TextFit(rp,node -> Special . Gauge . InfoText,strlen(node -> Special . Gauge . InfoText),&Extent,NULL,1,width,32767);
  103.  
  104.         LTP_PlaceText(handle,node -> Special . Gauge . InfoText,len,node -> Left + 2 + (width - Extent . te_Width) / 2,node -> Top + 1 + (height - rp -> Font -> tf_YSize) / 2 + rp -> Font -> tf_Baseline);
  105.  
  106.         LTP_SetPens(rp,handle -> TextPen,handle->BackgroundPen,JAM1);
  107.     }
  108.     else
  109.     {
  110.         if(node -> Current < percent)
  111.         {
  112.             LONG height    = node -> Height - (1 + handle -> InterHeight + handle -> RPort . TxHeight + 2 + 1);
  113.             LONG width    = node -> Width - (2 + 2);
  114.             LONG left    = (width * node -> Current) / 100;
  115.             LONG right    = (width * percent) / 100;
  116.  
  117.             if(right)
  118.             {
  119.                 LTP_SetAPen(rp,handle -> DrawInfo -> dri_Pens[FILLPEN]);
  120.                 RectFill(rp,node -> Left + 2 + left,node -> Top + 1,node -> Left + 2 + right - 1,node -> Top + 1 + height - 1);
  121.             }
  122.         }
  123.         else
  124.         {
  125.             if(node -> Current > percent)
  126.             {
  127.                 LONG height    = node -> Height - (1 + handle -> InterHeight + handle -> RPort . TxHeight + 2 + 1);
  128.                 LONG width    = node -> Width - (2 + 2);
  129.                 LONG left    = (width * percent) / 100;
  130.                 LONG right    = (width * node -> Current) / 100;
  131.  
  132.                 if(right)
  133.                 {
  134.                     LTP_SetAPen(rp,handle -> BackgroundPen);
  135.                     RectFill(rp,node -> Left + 2 + left,node -> Top + 1,node -> Left + 2 + right - 1,node -> Top + 1 + height - 1);
  136.                 }
  137.             }
  138.         }
  139.     }
  140.  
  141.     node -> Current = percent;
  142.  
  143.     LTP_PutStorage(node);
  144. }
  145. #endif
  146.